package com.tulele.vtool.handler;

import com.google.common.collect.Maps;
import com.tulele.vtool.model.BTeamRelation;
import com.tulele.vtool.model.respEntity.RespData;
import com.tulele.vtool.model.respEntity.ReturnCode;
import com.tulele.vtool.service.BTeamRelationService;
import com.tulele.vtool.utils.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.Map;

/**
 * 团队关系信息表(BTeamRelation)表控制层
 *
 * @author makejava
 * @since 2020-09-09 16:09:59
 */
@Slf4j
@RestController
public class BTeamRelationHandle {
    /**
     * 服务对象
     */
    @Resource
    private BTeamRelationService bTeamRelationService;

    /**
     * 服务对象
     */
//    @Value("${spring.profiles.active}")
//    private String springProfilesActive;

    /**
     * 通过主键查询单条数据
     *
     * @param bTeamRelation
     * @return 单条数据
     */
    @PostMapping(value = "/selectOneBTeamRelationById", produces = "application/json;charset=UTF-8")
    public RespData selectOneBTeamRelationById(@RequestHeader("userId") String userId, @RequestBody BTeamRelation bTeamRelation) {

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(1);
        resultMap.put("bTeamRelationService", this.bTeamRelationService.queryById(bTeamRelation.getId()));

        RespData respData = new RespData();
        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("查询成功");
        return respData;
    }

    /**
     * 测试插入BTeamRelation一个实体
     *
     * @param
     * @return 单条数据
     */
    @GetMapping("insertOneBTeamRelation")
    public BTeamRelation insertOneBTeamRelation() {
        BTeamRelation bTeamRelation = new BTeamRelation();
        bTeamRelation.setTeamId(1000);//团队ID
        bTeamRelation.setTeamName("测试团队名称~");//团队名称
        bTeamRelation.setUserId(1226314);//成员userId
        bTeamRelation.setGzhCode("test");//公众号标识
        bTeamRelation.setUserTeamNow(1);//当前所属团队 0-离开 1-正在
        bTeamRelation.setInviterId(null);//邀请人userId
        bTeamRelation.setTeamRole(0);//成员角色 0-团队普通成员 1-团队管理员 2-团队队长
        bTeamRelation.setUserFlag(1);//展示状态（0停用 1正常）
        bTeamRelation.setInviterId(null);//邀请人userId
        bTeamRelation.setCreateTime(DateUtil.getCurDate());//创建时间
        bTeamRelation.setUpdateTime(DateUtil.getCurDate());//更新时间
        bTeamRelation.setTeamRemark("测试团队成员备注");//备注

        return this.bTeamRelationService.insert(bTeamRelation);
    }

    /**
     * 添加一个好友到团队
     *
     * @param bTeamRelation
     * @return 单条数据
     */
    @PostMapping(value = "/addOneBTeamRelationById", produces = "application/json;charset=UTF-8")
    public RespData addOneBTeamRelationById(@RequestHeader("userId") String userId, @RequestBody BTeamRelation bTeamRelation) {

        Map<String, Object> resultMap = Maps.newHashMapWithExpectedSize(1);
        resultMap.put("bTeamRelationService", this.bTeamRelationService.queryById(bTeamRelation.getId()));

        RespData respData = new RespData();
        respData.setData(resultMap);
        respData.setCode(ReturnCode.NORMAL_SUCC);
        respData.setMsg("查询成功");
        return respData;
    }

}
